/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bbd.crawler.url;

import bbd.crawler.url.fwk.BaseURLHandler;

import java.util.ArrayList;

/**
 *
 * @author amochakr
 */
public class SimpleURLAppendHandler extends BaseURLHandler {

    private ArrayList valueList = null;

    private int index = -1;
    
    //--------------------------------------------------------------------------
    /** Javadoc here */
    public boolean hasNext() {

        return ( index > -1
                   && index < valueList.size() );

    } // end method hasNext

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public String getUrl() {
        
        String url = null;

        if ( hasNext() ) {

            url = getOriginalURL().concat (
                                        getFormattedValue (
                                            (String) valueList.get (index)
                                        )
                                    );
            
            index ++;
        }
        
        return url;

    } // end method getUrl

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public void init ( String url, ArrayList values ) {

        setOriginalURL (url);

        if ( values != null 
              && values.size() > 0 )
        {
            index = 0;
            
            valueList = values;
        }

    } // end method init

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public String getcurrentValue() {

        return (String) valueList.get (index);

    } // end method getcurrentValue

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public ArrayList getcurrentValues() {
        throw new UnsupportedOperationException ("Not supported yet.");
    } // end method getcurrentValues
    
} // end class SimpleURLAppendHandler
